import {BrowserWindow, nativeTheme, shell} from "electron";
import path from "node:path";
import {newBrowserWindow} from "./utils";

export function showAboutDialog(parent: BrowserWindow) {
    const dialog = newBrowserWindow({
        resizable: false,
        minimizable: false,
        maximizable: false,
        // height: 290,
        // width: 350,
        show: false,
        useContentSize: true,
        skipTaskbar: true,
        backgroundColor: nativeTheme.shouldUseDarkColors ? "black" : "white",
        webPreferences: {
            enableRemoteModule: true,
            nodeIntegration: true,
            contextIsolation: false
        },
        parent
    });
    const cssName = nativeTheme.shouldUseDarkColors ? "antd.dark.min.css" : "antd.min.css";
    dialog.loadURL(
        `file://${path.resolve(__dirname, "../renderer/pages/about/about.html")}?cssName=${cssName}`
    ).then(() => dialog.show());
}

export function showHelpDialog(parent: BrowserWindow) {
    shell.openExternal("https://gitee.com/iamhefang/mhosts/wikis").catch(() => {
        const dialog = new BrowserWindow({
            resizable: false,
            minimizable: false,
            maximizable: false,
            height: 768, width: 1024,
            show: false,
            skipTaskbar: true,
            backgroundColor: nativeTheme.shouldUseDarkColors ? "black" : "white",
            webPreferences: {
                nodeIntegration: true,
                contextIsolation: false
            },
            parent
        });
        dialog.loadURL("https://gitee.com/iamhefang/mhosts/wikis")
            .then(() => dialog.show())
    })
}